using Common;
using Common.NetWork;

using GRPCDemo.Models;
using GRPCDemo.Protocol;

namespace GRPCDemo.Network
{
    public class NetSession : INetSession
    {
        public User? User { get; set; }


        private NetMessage? _message;
        public NetMessageResponse Response
        {
            get
            {
                if (_message == null)
                    _message = new NetMessage();

                if (_message.Response == null)
                    _message.Response = new NetMessageResponse();

                return _message.Response;
            }
        }

        public byte[]? GetResponse()
        {
            if (_message != null)
            {

                byte[] data = PackageHelper.PackMessage(_message);
                this._message = null;
                return data;
            }

            return null;
        }
    }
}
